#include "cPlayer.h"
#include "../Game.h"
#include "../../Input/InputAction.h"
#include "../InputManager.h"
#include "../GraphicManager.h"

void cPlayer::Update( float lfTimestep ) {
	int luiX = GetX();
	int luiY = GetY();

	cLevel &lLevel = cGame::Get().GetLevel();

	const cInputAction& lActionUp = cInputManager::Get().GetAction( eIA_MoveNorth);
	if (lActionUp.GetBecomeReleased()) {
		if (lLevel.GetMessageOn())
			lLevel.IncrementActionsExecuted();
		luiY--;
	}
	const cInputAction& lActionRight = cInputManager::Get().GetAction( eIA_MoveEast);
	if (lActionRight.GetBecomeReleased()) {
		if (lLevel.GetMessageOn())
			lLevel.IncrementActionsExecuted();
		luiX++;
	}
	const cInputAction& lActionDown = cInputManager::Get().GetAction( eIA_MoveSouth);
	if (lActionDown.GetBecomeReleased()) {
		if (lLevel.GetMessageOn())
			lLevel.IncrementActionsExecuted();
		luiY++;
	}
	const cInputAction& lActionLeft = cInputManager::Get().GetAction( eIA_MoveWest);
	if (lActionLeft.GetBecomeReleased()) {
		if (lLevel.GetMessageOn())
			lLevel.IncrementActionsExecuted();
		luiX--;
	}
	
	if ( !lLevel.IsWall( luiX, luiY ) ) {
		muiX = luiX;
		muiY = luiY;
	}	 
}

void cPlayer::Render() {
	cGraphicManager & lGraphic = cGraphicManager::Get();

	lGraphic.SetColor(eLightRed, eBlack);
	lGraphic.WriteChar(GetX(), GetY(), GetSymbol());

}